import 'package:flutter/material.dart';
import 'package:flutter_svg/svg.dart';
import 'package:get/get.dart';
import 'package:mtf/app/modules/home_module/home_controller.dart';
import 'package:mtf/app/modules/news_module/news_controller.dart';
import 'package:mtf/app/modules/stock_market_module/stock_market_controller.dart';
import 'package:mtf/app/theme/app_colors.dart';

import '../../../R.dart';
/**
 * GetX Template Generator - fb.com/htngu.99
 * */

class homePage extends GetView<homeController> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      extendBodyBehindAppBar: true,
      appBar: AppBar(
        toolbarHeight: 0,
        elevation: 0,
      ),
      bottomNavigationBar: _buildBottomNavigationBar(),
      body: _buildPageView(),
    );
  }

  Widget _buildBottomNavigationBar() {
    return Obx(() => BottomNavigationBar(
          selectedItemColor: c_f12f38,
          unselectedItemColor: c_333333,
          items: <BottomNavigationBarItem>[
            BottomNavigationBarItem(
              label: "首页",
              icon: SvgPicture.asset(controller.currentPage == 0
                  ? R.assetsImgIcSvgHomeOn
                  : R.assetsImgIcSvgHome),
            ),
            BottomNavigationBarItem(
              label: "行情",
              icon: SvgPicture.asset(controller.currentPage == 1
                  ? R.assetsImgIcSvgStockMarketOn
                  : R.assetsImgIcSvgStockMarket),
            ),
            BottomNavigationBarItem(
              label: "我的",
              icon: SvgPicture.asset(controller.currentPage == 2
                  ? R.assetsImgIcSvgMineOn
                  : R.assetsImgIcSvgMine),
            ),
          ],
          currentIndex: controller.currentPage,
          type: BottomNavigationBarType.fixed,
          onTap: (int index) => controller.switchBottomTabBar(index),
        ));
  }

  Widget _buildPageView() {
    Get.put(newsController());
    Get.put(stockMarketController());
    return PageView(
      //禁止滑动
      //physics: const NeverScrollableScrollPhysics(),
      children: controller.tabPageBodies,
      controller: controller.pageController,
      onPageChanged: (index) => controller.onPageChanged(index),
    );
  }
}
